package design2;

/**
 * BinaryOperation 测试类 - 设计二版本
 */
public class BinaryOperationTester {
    
    public static void main(String[] args) {
        System.out.println("=== 设计二测试开始 ===");
        
        // 测试多态
        testPolymorphism();
        
        // 专门测试加法
        additionOperationTester();
        
        // 专门测试减法  
        substractOperationTester();
        
        System.out.println("=== 设计二测试完成 ===");
    }
    
    /**
     * 测试多态特性
     */
    public static void testPolymorphism() {
        System.out.println("\n--- 多态测试 ---");
        
        // 使用父类引用指向子类对象
        BinaryOperation bop;
        bop = new AdditionOperation();
        System.out.println("加法算式: " + bop + " 结果: " + bop.calculate());
        
        bop = new SubstractOperation();
        System.out.println("减法算式: " + bop + " 结果: " + bop.calculate());
    }
    
    /**
     * 专门测试加法算式
     */
    public static void additionOperationTester() {
        System.out.println("\n--- 加法算式测试 ---");
        
        BinaryOperation bop;
        bop = new AdditionOperation();
        
        System.out.println("创建的加法算式: " + bop);
        System.out.println("计算结果: " + bop.calculate());
        System.out.println("合法性检查: " + bop.checkingCalculation());
        
        // 测试多个加法算式
        System.out.println("\n生成5个加法算式:");
        for (int i = 0; i < 5; i++) {
            bop = new AdditionOperation();
            System.out.println("  " + (i+1) + ". " + bop.toString());
        }
    }
    
    /**
     * 专门测试减法算式
     */
    public static void substractOperationTester() {
        System.out.println("\n--- 减法算式测试 ---");
        
        BinaryOperation bop;
        bop = new SubstractOperation();
        
        System.out.println("创建的减法算式: " + bop);
        System.out.println("计算结果: " + bop.calculate());
        System.out.println("合法性检查: " + bop.checkingCalculation());
        
        // 验证减法结果非负
        int result = bop.calculate();
        System.out.println("结果非负验证: " + (result >= 0));
        
        // 测试多个减法算式
        System.out.println("\n生成5个减法算式:");
        for (int i = 0; i < 5; i++) {
            bop = new SubstractOperation();
            System.out.println("  " + (i+1) + ". " + bop.toString());
        }
    }
}